<?php
	require_once "include/User.php";
	require_once "include/Article.php";
	require_once "include/Template.php";
	require_once "include/backend/UserDb.php";
	require_once "include/backend/ArticlesDb.php";
	
	if      ($_GET['u'] == null) // if none are provided there's nothing to show
		header("Location: ./");
	else if (strpos($_GET['u'], ";")) // to prevent SQL injections
		header("Location: ./");
	
	// Now we can start with the actual page. Setting logged in user
	$page = new Template();
	session_start();
	$page->setUser($_SESSION['user']);
	
	$users = new UserDb();
	$user = $users->get(new User(array('username' => addslashes($_GET['u']))));
	
	if ($_GET['act'] == "edit" && isset($user->name)) {
		if ($_SESSION['user']->name != $user->name)
			header("Location: ./");
		$page->addContent($_SESSION['user']->editInfoHTML());
	}
	else if (isset($user->name)) {
		$user->genHTML();
		$page->addContent($user->getHTML());
		
		$articles = new ArticlesDb();
		$content = $articles->getByAuthor(8, $user);
		
		if ($content != false)
			for ($i = 0; $i < count($content); $i++)
				$page->addContent($content[$i]->getHTML());
	}
	echo $page->getHTML();
?>
